package org.summerframework.component.note.template.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.summerframework.component.mybatisplus.AbstractBasePlusService;
import org.summerframework.component.note.template.model.dao.NoteTemplateDAO;
import org.summerframework.component.note.template.model.domain.NoteTemplateDO;
import org.summerframework.component.note.template.service.NoteTemplateService;
import org.summerframework.component.note.template.service.dto.NoteTemplateDTO;
import org.summerframework.component.note.template.service.dto.NoteTemplateQueryDTO;

import java.util.Objects;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service("noteTemplateService")
public class NoteTemplateServiceImpl extends AbstractBasePlusService<NoteTemplateDAO, NoteTemplateDTO, NoteTemplateQueryDTO, NoteTemplateDO> implements NoteTemplateService {

    @Override
    public Wrapper<NoteTemplateDO> getWrapper(NoteTemplateQueryDTO query) {
        return Wrappers.<NoteTemplateDO>lambdaQuery()
                .like(StringUtils.isNotBlank(query.getSearchCode()), NoteTemplateDO::getCode, query.getSearchCode())
                .eq(StringUtils.isNotBlank(query.getCode()), NoteTemplateDO::getCode, query.getCode())
                .orderBy(Objects.nonNull(query.getOrderByCreateTime()), query.getOrderByCreateTime() != null ? query.getOrderByCreateTime() : false, NoteTemplateDO::getCreateTime)
                .like(StringUtils.isNotBlank(query.getSearchSignName()), NoteTemplateDO::getSignName, query.getSearchSignName())
                .eq(StringUtils.isNotBlank(query.getSignName()), NoteTemplateDO::getSignName, query.getSignName())
                .orderBy(Objects.nonNull(query.getOrderById()), query.getOrderById() != null ? query.getOrderById() : false, NoteTemplateDO::getId)
                .eq(Objects.nonNull(query.getType()), NoteTemplateDO::getType, query.getType())
                .eq(Objects.nonNull(query.getPlatformType()), NoteTemplateDO::getPlatformType, query.getPlatformType());
    }

    @Override
    public NoteTemplateDTO selectByCode(String code) {
        return selectOne(NoteTemplateQueryDTO.builder().code(code).build());
    }
}
